package com.blog.service.impl;

import com.blog.mapper.UserMapper;
import com.blog.pojo.User;
import com.blog.service.UserService;
import org.mindrot.jbcrypt.BCrypt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public User login(Map<String, String> map) {
        String username = map.get("username");
        String password = map.get("password");
        User user = userMapper.selectByUsername(username);
        if (user==null){
            return null;
        }
        if (BCrypt.checkpw(password,user.getPassword())) {
            return user;
        }
        return null;
    }
}
